﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using NetDon.OA.Interface;
using NetDon.OA.Interface.eLogistics;
using NetDon.Utilities;

namespace NetDon.OA.Portal.eLogisticsQuery
{
      [Navigation("报表查询", "付款台帐查询")]
    public partial class PaymentMachineAccountQuery : PageBase
    {
    

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {

                txtPaymentOrIncomeDateStart.Text =
              DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
                txtPaymentOrIncomeDateEnd.Text =
              DateTime.Now.ToString("yyyy-MM-dd");


                ddlCompany.InsertEmptyItem(ListEmptyType.Select);
                this.ddlCustomer.InsertEmptyItem(ListEmptyType.Select);
                if (!this.IsSuperRoles())
                {
                    ddlCompany.SelectedValue = CurrentApplicationContext.CompanyId.ToString();
                    ddlCompany.Enabled = false;
                }
            }
        }



        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            HttpContext.Current.Session["PaymentMachineAccountQuery"] = GetSearchCriteria();
            this.ScriptStartup("search();");

          
        }

        protected MachineAccountSearchReportCriteria GetSearchCriteria()
        {
            var criteria = new MachineAccountSearchReportCriteria
            {

            };
            if (!MiscUtilities.IsNullOrEmpty(ddlCompany.SelectedValue))
            {
                criteria.AreaId = ddlCompany.SelectedValue.ToGuid();
            }
            DateTime? dateStart = null, dateEnd = null;
            if (!string.IsNullOrEmpty(txtPaymentOrIncomeDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtPaymentOrIncomeDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPaymentOrIncomeDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtPaymentOrIncomeDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.PaymentOrIncomeDate = new Range<DateTime?>(dateStart, dateEnd);
            }

            if (!string.IsNullOrEmpty(txtOrderCode.Text))
            {
                criteria.OrderCode = txtOrderCode.Text.Trim();
            }

            if (!string.IsNullOrEmpty(txtTransportationPlanCode.Text))
            {
                criteria.TransportationPlanCode = txtTransportationPlanCode.Text.Trim();
            }

            if (!string.IsNullOrEmpty(ddlPaymentMethod.SelectedValue))
            {
                criteria.PaymentMethod = ddlPaymentMethod.SelectedValue.ToGuid();
            }
            if (!MiscUtilities.IsNullOrEmpty(ddlRouteTypeId.SelectedValue.ToGuid()))
            {
                criteria.RouteTypeId = ddlRouteTypeId.SelectedValue.ToGuid();
            }
            if (!string.IsNullOrEmpty(txtDriverDriverName.Text))
            {
                criteria.Driver = txtDriverDriverName.Text.Trim();
            }

            dateStart = null; dateEnd = null;
            if (!string.IsNullOrEmpty(txtActualShippingDateStart.Text.Trim()))
            {
                dateStart = DateTime.Parse(txtActualShippingDateStart.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtActualShippingDateEnd.Text.Trim()))
            {
                dateEnd = DateTime.Parse(txtActualShippingDateEnd.Text.Trim());
            }
            if (dateStart.HasValue || dateEnd.HasValue)
            {
                criteria.ActualShippingDate = new Range<DateTime?>(dateStart, dateEnd);
            }

            decimal invoiceAmountStart, invoiceAmountEnd;

            if (decimal.TryParse(txtDeductionAmountStart.Text, out invoiceAmountStart))
            {
                criteria.PendingShippingCostStart = invoiceAmountStart;
            }
            if (decimal.TryParse(txtDeductionAmountEnd.Text, out invoiceAmountEnd))
            {
                criteria.PendingShippingCostEnd = invoiceAmountEnd;
            }
            return criteria;
        }









    }
}